export function format<T>(format : string = "{y}-{m}-{d} {h}:{i}:{s}", time : any) {
    let this_date;
    time = time ? time : new Date();
    if (typeof time === "object") {
        this_date = time;
    } else {
        if ((typeof time === "string")) {
            if ((/^[0-9]+$/.test(time))) {
                time = parseInt(time);
            } else {
                time = time.replace(new RegExp(/-/gm), "/");
            }
        }

        if ((typeof time === "number") && (time.toString().length === 10)) {
            time = time * 1000;
        }
        this_date = new Date(time);
    }
    const formatObj : any = {
        y: this_date.getFullYear(),
        m: this_date.getMonth() + 1,
        d: this_date.getDate(),
        h: this_date.getHours(),
        i: this_date.getMinutes(),
        s: this_date.getSeconds(),
        a: this_date.getDay()
    };
    const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
        const value = formatObj[key];
        if (key === "a") {
            return ["日", "一", "二", "三", "四", "五", "六"][value];
        }
        return value.toString().padStart(2, "0");
    });
    return time_str;
};